<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: math functions</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
  $(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="aslogo_small.png"/></td>
  <td id="projectalign">
   <div id="projectname">AngelScript
   </div>
  </td>
    <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <span id="MSearchSelect"                onmouseover="return searchBox.OnSearchSelectShow()"                onmouseout="return searchBox.OnSearchSelectHide()">&#160;</span>
          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.6 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('doc_addon_math.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div><div class="header">
  <div class="headertitle"><div class="title">math functions </div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>Path:</b> /sdk/add_on/scriptmath/</p>
<p>This add-on registers the math functions from the standard C runtime library with the script engine. Use <code>RegisterScriptMath(asIScriptEngine*)</code> to perform the registration.</p>
<p>By defining the preprocessor word AS_USE_FLOAT=0, the functions will be registered to take and return doubles instead of floats.</p>
<p>The function <code>RegisterScriptMathComplex(asIScriptEngine*)</code> registers a type that represents a complex number, i.e. a number with real and imaginary parts.</p>
<h1><a class="anchor" id="doc_addon_math_1"></a>
Public script interface</h1>
<pre>
  // Trigonometric functions
  float cos(float rad);
  float sin(float rad);
  float tan(float rad);

  // Inverse trigonometric functions
  float acos(float val);
  float asin(float val);
  float atan(float val);
  float atan2(float y, float x);

  // Hyperbolic functions
  float cosh(float rad);
  float sinh(float rad);
  float tanh(float rad);

  // Logarithmic functions
  float log(float val);
  float log10(float val);

  // Power to
  float pow(float val, float exp);

  // Square root
  float sqrt(float val);

  // Absolute value
  float abs(float val);

  // Ceil and floor functions
  float ceil(float val);
  float floor(float val);

  // Returns the fraction
  float fraction(float val);

  // Approximate float comparison, to deal with numeric imprecision
  bool closeTo(float a, float b, float epsilon = 0.00001f);
  bool closeTo(double a, double b, double epsilon = 0.0000000001);

  // Conversion between floating point and IEEE 754 representations
  float  fpFromIEEE(uint raw); 
  double fpFromIEEE(uint64 raw);
  uint   fpToIEEE(float fp);
  uint64 fpToIEEE(double fp);
</pre><h2><a class="anchor" id="doc_addon_math_funcs"></a>
Functions</h2>
<p><b>cos, sin, tan</b></p>
<p>Calculates the trigonometric functions cosine, sine, and tangent. The input angle should be given in radian.</p>
<p><b>acos, asin, atan</b></p>
<p>Calculates the inverse of the trigonometric functions cosine, sine, and tangent. The returned angle is given in radian.</p>
<p><b>atan2</b></p>
<p>Calculates the inverse of the trigonometric function tangent. The input is the y and x proportions. The returned angle is given in radian.</p>
<p><b>cosh, sinh, tanh</b></p>
<p>Calculates the hyperbolic of the cosine, sine, and tangent. The input angle should be given in radian.</p>
<p><b>log, log10</b></p>
<p>Calculates the logarithm of the input value. log is the natural logarithm and log10 is the base-10 logarithm.</p>
<p><b>pow</b></p>
<p>Calculates the based raised to the power of exponent.</p>
<p><b>sqrt</b></p>
<p>Calculates the square root of the value.</p>
<p><b>abs</b></p>
<p>Returns the absolute value.</p>
<p><b>ceil, floor</b></p>
<p>ceil returns the closest integer number that is higher or equal to the input. Floor returns the closest integer number that is lower or equal to the input.</p>
<p><b>fraction</b></p>
<p>Returns the fraction of the number, i.e. what remains after taking away the integral number.</p>
<p><b>closeTo</b></p>
<p>Due to numerical errors with the binary representation of real numbers it is often difficult to do direct comparisons of two float values. The closeTo function will return true of the two values are almost equal, allowing for a small difference up to the size of the epsilon value.</p>
<p><b>fpFromIEEE, fpToIEEE</b></p>
<p>Translates the float to and from IEEE 754 representation. This can be used if one wishes to directly inspect or manipulate the floating point value in the binary representation.</p>
<h2><a class="anchor" id="doc_addon_math_complex"></a>
The complex type</h2>
<pre>
  // This type represents a complex number with real and imaginary parts
  class complex
  {
    // Constructors
    complex();
    complex(const complex &amp;in);
    complex(float r);
    complex(float r, float i);

    // Equality operator
    bool opEquals(const complex &amp;in) const;

    // Compound assignment operators
    complex &amp;opAddAssign(const complex &amp;in);
    complex &amp;opSubAssign(const complex &amp;in);
    complex &amp;opMulAssign(const complex &amp;in);
    complex &amp;opDivAssign(const complex &amp;in);

    // Math operators
    complex opAdd(const complex &amp;in) const;
    complex opSub(const complex &amp;in) const;
    complex opMul(const complex &amp;in) const;
    complex opDiv(const complex &amp;in) const;

    // Returns the absolute value (magnitude)
    float abs() const;

    // Swizzle operators
    complex get_ri() const;
    void set_ri(const complex &amp;in);
    complex get_ir() const;
    void set_ir(const complex &amp;in);

    // The real and imaginary parts
    float r;
    float i;
  }
</pre><p><b>complex</b></p>
<p>The constructors allow for implicit construction, making a copy, implicit conversion from float, and explicit initialization from two float values.</p>
<p><b>=, !=</b></p>
<p>Compares two complex values.</p>
<p><b>=, +=, -=, *=, /=</b></p>
<p>Assign and compound assignment of complex values.</p>
<p><b>+, -, *, /</b></p>
<p>Math operators on complex values.</p>
<p><b>abs</b></p>
<p>Returns the absolute (magnitude) of the complex value.</p>
<p><b>r, i</b></p>
<p>Retrieves the real and imaginary part of the complex value.</p>
<p><b>ri, ir</b></p>
<p>Swizzle operators return a complex value with the ordering of the real and imaginary parts as indicated by the name. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Sun May 21 2023 10:12:39 for AngelScript by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.6 </li>
  </ul>
</div>
</body>
</html>
